import BaseUtil from '@/BaseUtil';
import SelectUtil from '@/SelectUtil';
import TextTagUtil from '@/TextTagUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
import GameMonsters from 'code/Scripts/GameMonster';
/**
 * 呼朋狗友 (Boss)
 **/
export default class BossSpell_CallFriend extends AbilityBase {
    static instance: BossSpell_CallFriend;
    constructor(id: string = 'Mgt1') {
        super(id);
        BossSpell_CallFriend.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    onMissileReach(p: 定点投射物参数<effect>) {
        DestroyEffect(AddSpecialEffect('Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl', p.curX, p.curY));
        DamageSystemInstance.applyAoeDamageByUnit(p.caster, 150, 500, { magicType: 'fire' }, GetUnitX(p.missileUnit), GetUnitY(p.missileUnit));
        DestroyEffect(p.other);
        p.other = null;
        GameMonsters.create('nkot', p.curX, p.curY);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        TextTagUtil.text('呼朋狗友', source, 15, 1.5, 255, 255, 100);
        let marks: { x: number; y: number; mark: effect }[] = [];
        let es = SelectUtil.getEnemyUnitsInRange(source, 1000);
        let count = es.length > 5 ? 5 : es.length;
        for (let i = 0; i < count; i++) {
            marks.push({
                x: GetUnitX(es[i]),
                y: GetUnitY(es[i]),
                mark: AddSpecialEffect(BossAbilityManagerInstance.SpellMark, GetUnitX(es[i]), GetUnitY(es[i])),
            });
        }
        BaseUtil.runLater(1, () => {
            for (let i = 0; i < marks.length; i++) {
                MovementCommon.定点投射物({
                    missile: 'units\\creeps\\Kobold\\Kobold.mdl',
                    caster: source,
                    tarX: marks[i].x,
                    tarY: marks[i].y,
                    radian: 0.35,
                    speed: 500,
                    onReachTarget: this.onMissileReach.bind(this),
                    other: marks[i].mark,
                });
            }
            marks = null;
            source = null;
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
